import { createRouter, createWebHistory } from 'vue-router';

const router = createRouter({
  // 指定统一路由前缀
  // note: 使用 vue-router 的路由访问都不需要添加 /mobile/ 前缀，但是如果使用 window.location.href 进行跳转，需要添加前缀
  history: createWebHistory('/mobile/'),
  // history: createWebHistory(),
  routes: [
    {
      path: '/',
      redirect: '/user/homepagesquare',
    },
    {
      path: '/login',
      component: () => import('@/views/Login/index.vue'),
    },
    {
      path: "/user",
      component: () => import("@/views/Square/index.vue"),
      children: [
        {
          path: "homepagesquare",
          component: () => import("@/views/Square/HomeSquare/index.vue"),
        },
        {
          path: "learning_home",
          name: "learning_home",
          component: () => import("@/views/Square/LearningSquare/Home/index.vue"),
        },

        {
          path: "dachuang",
          component: () => import("@/views/Square/InnovationSquare/projectDisplay/home/index.vue"),
        },
        {
          path: "dachuang/project",
          component: () => import("@/views/Square/InnovationSquare/projectDisplay/home/index.vue"),
          // children: [
          //   {
          //     path: "xiangqing/:projectId",
          //     name: "projectDetails",
          //     component: () => import("@/views/Square/InnovationSquare/projectDisplay/details/index.vue"),
          //   },
          // ],
        },
        {
          path: "dachuang/project/xiangqing/:projectId",
          name: "projectDetails",
          component: () => import("@/views/Square/InnovationSquare/projectDisplay/details/index.vue"),
        },
        {
          path: "dachuang/saishi",
          component: () => import("@/views/Square/InnovationSquare/competitionInfo/home/index.vue"),
          props: true,
          // children: [
          //   {
          //     path: "xiangqing/:competitionId",
          //     name: "competitionDetails",
          //     component: () => import("@/views/Square/InnovationSquare/competitionInfo/details/index.vue"),
          //   },
          // ],
        },
        {
          path: "dachuang/saishi/xiangqing/:competitionId",
          name: "competitionDetails",
          component: () => import("@/views/Square/InnovationSquare/competitionInfo/details/index.vue"),
        },
        // 数据广场
        {
          path: "datasquare",
          component: () => import("@/views/Square/DataSquare/Home/index.vue"),
        },
      ],
    },
    // 数据广场相关
    {
      path: "/datasquare",
      children: [
        // 数据广场详情
        {
          path: "details/:datasetId",
          name: "DataDetail",
          component: () => import("@/views/Square/DataSquare/Details/index.vue"),
          props: true, // 允许通过 props 传递路由参数
        },
      ],
    },
    {
      path: "/learning",
      children: [
        {
          path: "data/:id",
          name: "LearningData",
          component: () => import("@/views/Square/LearningSquare/tree/true/index.vue"),
        },
        {
          path: "xiangqing/:courseId/:folderId",
          name: "learning/xiangqing",
          component: () =>
            import("@/views/Square/LearningSquare/details/index.vue"),
          props: route => ({ courseId: route.params.courseId, folderId: route.params.folderId }),
        },
        {
          path: "details/:courseId/:folderId/:sourceId/:filePath",
          name: "LearningDetails",
          component: () => import("@/views/Square/LearningSquare/Lesson/index.vue"),
          props: route => ({ sourceId: route.params.sourceId, courseId: route.params.courseId, folderId: route.params.folderId, filePath: route.params.filePath }),
        },
      ],
    },
    // 个人中心
    {
      path: "/personalSpace",
      name: "personalSpace",
      component: () => import("@/views/PersonalSpace/index.vue"), // 父级组件包含侧边栏和子页面内容
      children: [
        // 个人信息
        {
          path: "personalInfo",
          name: "personalInfo",
          component: () => import("@/views/PersonalSpace/PersonalInfo/index.vue"),
        },
        // 训练营集合
        {
          path: "trainingSet",
          name: "trainingSet",
          component: () => import("@/views/PersonalSpace/TrainingSet/index.vue"),
        },
        // 训练营详情
        {
          path: "trainingDetail/:coursesTag",
          name: "trainingDetail",
          component: () => import("@/views/PersonalSpace/TrainingDetail/index.vue"),
          props: route => ({ trainingId: route.params.coursesTag }),
        },
      ],
    },
  ],
});
export default router;
